<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <!-- 引入样式 -->
  <link rel="stylesheet" href="../../plugins/element-ui/index.css" />
  <!-- 开发环境版本，包含了有帮助的命令行警告 -->
  <script src="../../plugins/vue/vue.js"></script>
  <!-- 引入组件库 -->
  <script src="../../plugins/element-ui/index.js"></script>
  <!-- 引入axios -->
  <script src="../../plugins/axios/axios.min.js"></script>
  <script src="../../js/request.js"></script>
  <title>Document</title>
</head>
<body>
<div id="app" align="left">
  <div id="main" style="width: 1000px;height:600px;"></div>
  <div>
    说明：把统计结果发送到邮箱中
    <el-input
            v-model="input"
            placeholder="请输入邮箱地址"
            style="width: 250px"
            clearable
            @keyup.enter.native="sendemail"
    >
      <i
              slot="prefix"
              class="el-input__icon el-icon-search"
              style="cursor: pointer"
              @click="sendemail"
      ></i>
    </el-input>
  </div>
</div>
<script>
  new Vue({
    el: '#app',
    data() {
      return {
        input: ''
      }
    },
    computed: {},
    created() {
    },
    mounted() {
    },
    methods: {
      async sendemail() {
        const params = {
          email: this.input ? this.input : undefined
        }
        await sendEmail(params).then(res => {
          if (String(res.code) === '1') {
            this.$message.success(res.data);
          }
        }).catch(err => {
          this.$message.error('请求出错了：' + err)
        })
      }
    }
  })
</script>
<script src="../../api/countSale.js"></script>
<script src="../../js/echarts.js"></script>
<script type="text/javascript">
  var chartDom = document.getElementById('main');
  var myChart = echarts.init(chartDom, 'dark');
  var option;
  option = {
    title: {
      text: '不同菜品销售数据分析',
      subtext: '菜品类别',
      left: 'center'
    },
    tooltip: {
      trigger: 'item'
    },
    legend: {
      orient: 'vertical',
      left: 'left'
    },
    series: [
      {
        name: 'Access From',
        type: 'pie',
        radius: '50%',
        data: [
          { value: 1048, name: 'Search Engine' },
          { value: 735, name: 'Direct' },
          { value: 580, name: 'Email' },
          { value: 484, name: 'Union Ads' },
          { value: 300, name: 'Video Ads' }
        ],
        emphasis: {
          itemStyle: {
            shadowBlur: 10,
            shadowOffsetX: 0,
            shadowColor: 'rgba(0, 0, 0, 0.5)'
          }
        }
      }
    ]
  };
  option && myChart.setOption(option);

  //发送ajax请求数据
  getCountSaleByDish().then(res => {
    if (String(res.code) === '1') {
      this.option.series[0].data=res.data;
      option && myChart.setOption(option);
    } else {
      this.$message.error(res.msg || '操作失败')
    }
  }).catch(err => {
    this.$message.error('请求出错了：' + err)
  })
</script>
</body>
</html>